Display Output in Label Controls and PictureBox Controls
- You will add functionality (code) to each button so text will be displayed in the answerLabel
- To display output in a label control you use the following code:
- answerLabel.Text = "Exact text of the answer"
- Add code to the Yes button: Double-click the Yes button
- Add the code: answerLabel.Text = "It's lots of fun!"
- Add code to the No button: answerLabel.Text = "Are you kidding???"
- Both codes are as illustrated here:
- then "Save All"
PictureBox Controls
Create a new Windows Form Project named PictureBoxControls in your C# project folder.
- Change the Form1 Text to "Exploring PictureBox Controls"
- Add a PictureBox to the form as shown here:
- Add an Image to the PictureBox
- Select the Image property
- Click on the builder button as shown here:
- Click on Import; browse to locate any image in your computer and then click OK
- Select the SizeMode property: Select StretchImage (the whole image will show)
- Resize the image as you see fit
- Make the image 'Clickable'
- When the 'Cat' image is clicked, a MessageBox saying ‘Meow’ will be displayed
- Double-click the image and type the code: MessageBox.Show(“Meow”); See the code below:
- Save all and Run the program
For more details, please contact me here.
Date of last modification: 2021